#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e5+10;
void solve()
{
	int n;
	cin>>n;
	string s;
	string b;
	cin>>s>>b;
	int cnt2=1;
	int l=0,r=n-1;
	vector<int> v;
	int cnt1=0;
	while(cnt2<=n)
	{
		if(cnt1%2==1)
		{	
			if((s[l]-48+cnt1)%2!=b[n-cnt2]-48)
			{
				if((s[r]-48+cnt1)%2==b[n-cnt2]-48)
				{
					s[r]=(s[r]+1)%2;
					v.push_back(1);
				}
				v.push_back(n-cnt2+1);
				cnt1++;
				r--;
			}
			else l++;
		}
		else
		{
			if((s[r]-48+cnt1)%2!=b[n-cnt2]-48)
			{
			    if((s[l]-48+cnt1)%2==b[n-cnt2]-48)
				{
					s[l]=(s[l]+1)%2;
					v.push_back(1);
				}
				v.push_back(n-cnt2+1); 
				cnt1++;
				l++;
			}
			else r--;
		}
		cnt2++;
	}
	cout<<v.size()<<' ';
	for(auto it:v)
	{
		cout<<it<<' ';
	}
	cout<<endl;
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	} 

	return 0;
}

